package com.example.utils.util.Imageurl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @ClassName Pic
 * @Author xiaojiang
 * @Date 2021/11/25 下午 18:04
 */
public class Pic {



    public static void main(String[] args){
        String url = "https://doctrans-service.youdao.com/trandoc/doc/getFullOriginModeImg?docKey=97264D2AC3E345E3958272608A5921DA&pageName=tran-66.jpeg&src=fanyiweb&isCheckTermUpdate=false&isUseTerm=true";

        String str = SendGET(url);
        System.out.println("------------------------------------");
        System.err.print(str);
    }
    public static String SendGET(String url){
        String result="";//访问返回结果
        BufferedReader read=null;//读取访问结果
        try {
            //创建url
            URL realurl=new URL(url);
            //打开连接
            URLConnection connection=realurl.openConnection();
            connection.setRequestProperty("Cookie", "OUTFOX_SEARCH_USER_ID_NCOO=1126866298.4504936; OUTFOX_SEARCH_USER_ID=\"1848707053@10.105.137.203\"; JSESSIONID=abc-nLzzSb6YLbId82R0x; NTES_SESS=izFJC7QXRuzv6sEiIDcQaqi9lFQOp1h9uYXd4XnJU6Ru8Ftg8d_0OTswjY2Pvq.94jZCufMmozld.64q6Ic7eUbSKjrs3djTPc60sHPuAAhOdhEuo2669MB5zKST8BQK.oozbEqZ6Nj36DjR7xP4AiR6VNZd2RyEOfYBLR6Gp3ea3ICk37gUsCpyFksKFor2IcniSuMjoRw8ek584jHzXlOmik99ITQhy; S_INFO=1637811894|0|3&80##|m15378758370; P_INFO=m15378758370@163.com|1637811894|0|youdao_fanyi|00&99|bej&1626417752&note_client#bej&null#10#0#0|153370&1||15378758370@163.com; DICT_SESS=v2|gcwbmA3kGWwZ64eyRHUWRq4PLeFOLgy06Zh4JShMTBROWhf6ShLeu0kE64qKOMpy0z50LJz0fJ4RJykMpL0Meu0lGnfkEhfPy0; DICT_PERS=v2|urscookie||DICT||web||604800000||1637811895106||124.14.224.45||m15378758370@163.com||TunfQLO4eZ0Y5Rfw4RfTy0UW64Tyh4640pFkMJuhMpZ0q4RMqShLwLRwF0MkA64eB0lY0HzW0MTyRqyRHUM0fp40; DICT_LOGIN=3||1637811895112");

            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            //建立连接
            connection.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 遍历所有的响应头字段，获取到cookies等
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            read = new BufferedReader(new InputStreamReader(
                    connection.getInputStream(),"UTF-8"));
            String line;//循环读取
            while ((line = read.readLine()) != null) {
                result += line;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(read!=null){//关闭流
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }










}
